package leetcode.tree;

import java.util.ArrayList;
import java.util.List;

public class Solution {

    public List<Integer> preorderTraversal(TreeNode root) {
            List<Integer> list = new ArrayList<>();
            back(list,root);
            return list;
    }

    public void back(List<Integer> list, TreeNode node){
        if (node == null) {
            return;
        }
        list.add(node.val);
        back(list,node.left);
        back(list,node.right);
    }
}
